package o;

import android.text.TextUtils;
import android.widget.TabHost.TabSpec;
import androidx.fragment.app.Fragment;
import com.huawei.appgallery.agwebview.api.ui.IWebViewFragmentProtocol;
import com.huawei.appgallery.foundation.service.common.protocol.AppListFragmentProtocol;
import com.huawei.appgallery.foundation.service.common.protocol.request.AppListFragmentRequest;
import com.huawei.appgallery.foundation.ui.framework.titleframe.bean.BaseTitleBean;
import com.huawei.hms.support.hianalytics.HiAnalyticsConstant;
import java.util.List;

public class HomePageAdapter extends ewk {
    private List<ckm> ˊ;

    public HomePageAdapter(List<ckm> list) {
        this.ˊ = list;
    }

    public int ˎ() {
        if (this.ˊ == null || this.ˊ.isEmpty()) {
            return 0;
        }
        return this.ˊ.size();
    }

    public Fragment ˎ(int i) {
        Fragment fragment;
        Fragment fragment2 = null;
        if (this.ˊ == null || this.ˊ.isEmpty()) {
            Logger.e("HomePageAdapter", "getItem error navColumns " + this.ˊ);
            fragment = null;
        } else {
            ckm o_ckm = (ckm) this.ˊ.get(i);
            if (o_ckm != null) {
                String ˊ = cju.ˊ(o_ckm.ˊ());
                if (ˊ == null) {
                    ˊ = "applist.fragment";
                }
                if (o_ckm.ˊ() == null || !(o_ckm.ˊ().startsWith("mw4c") || o_ckm.ˊ().startsWith("html"))) {
                    fragment2 = ˏ(o_ckm, ˊ);
                    if (fragment2 instanceof cid) {
                        ((cid) fragment2).ॱᐝ(4);
                    }
                    Logger.ˎ("HomePageAdapter", "Create AppListFragment with position:" + i);
                } else {
                    fragment2 = ˋ(o_ckm);
                }
            }
            fragment = fragment2;
        }
        if (fragment != null) {
            return fragment;
        }
        fragment = new Fragment();
        Logger.e("HomePageAdapter", "getItem error new Fragment(), position = " + i);
        return fragment;
    }

    private Fragment ˏ(ckm o_ckm, String str) {
        cjo appListFragmentProtocol = new AppListFragmentProtocol();
        AppListFragmentRequest appListFragmentRequest = new AppListFragmentRequest();
        appListFragmentRequest.ˊ(true);
        appListFragmentRequest.ˋ(o_ckm.ˊ());
        appListFragmentRequest.ॱ(o_ckm.ᐝ());
        appListFragmentRequest.ˊ(o_ckm.ʻ());
        appListFragmentRequest.ॱॱ(o_ckm.ˋ());
        appListFragmentRequest.ʻ(true);
        appListFragmentRequest.ॱॱ(false);
        appListFragmentRequest.ʻ("homepage");
        appListFragmentRequest.ˏॱ(o_ckm.ॱ());
        appListFragmentRequest.ˏ(o_ckm.ʽ());
        appListFragmentRequest.ͺ(o_ckm.ॱॱ());
        String ॱ = cju.ॱ(o_ckm.ˊ());
        cje o_cje;
        BaseTitleBean baseTitleBean;
        if ("gss|discovery".equals(ॱ) || "gss|home".equals(ॱ)) {
            o_cje = new cje();
            o_cje.ˋ("forum_msg_search_title");
            baseTitleBean = new BaseTitleBean();
            baseTitleBean.ˋ("homepage");
            baseTitleBean.ˎ(o_ckm.ˊ());
            o_cje.ˎ(baseTitleBean);
            appListFragmentRequest.ˏ(o_cje);
        } else if ("gss|forum_home_2".equals(ॱ) || "gss|game_community".equals(ॱ)) {
            o_cje = new cje();
            o_cje.ˋ("forum_title");
            baseTitleBean = new BaseTitleBean();
            baseTitleBean.ˋ("homepage");
            baseTitleBean.ˎ(o_ckm.ˊ());
            o_cje.ˎ(baseTitleBean);
            appListFragmentRequest.ˏ(o_cje);
        }
        appListFragmentProtocol.ˏ(appListFragmentRequest);
        return cjk.ˎ().ˊ(new cjm(str, appListFragmentProtocol));
    }

    private Fragment ˋ(ckm o_ckm) {
        fjb ˎ = fho.ˏ().ˋ("AGWebView").ˎ("webview_fragment");
        IWebViewFragmentProtocol iWebViewFragmentProtocol = (IWebViewFragmentProtocol) ˎ.ˊ();
        String ˊ = o_ckm.ˊ();
        Object substring = ˊ.substring(ˊ.indexOf(HiAnalyticsConstant.REPORT_VAL_SEPARATOR) + 1);
        if (!TextUtils.isEmpty(substring)) {
            iWebViewFragmentProtocol.setUrl(substring);
        }
        return fjm.ˏ(fiu.ˊ().ˋ(ContentManager.getInstant().getContext(), ˎ)).ˏ();
    }

    public void ˏ(int i, Fragment fragment, Fragment fragment2) {
        if (fragment2 instanceof ciy) {
            ((ciy) fragment2).ʽˊ();
        }
        ॱ(fragment2, 4);
        if (fragment instanceof ciy) {
            ((ciy) fragment).ˋ(i);
        }
        ॱ(fragment, 0);
        ॱ(i);
    }

    public boolean ˎ(int i, TabSpec tabSpec) {
        if (!(this.ˊ == null || this.ˊ.isEmpty())) {
            ckm o_ckm = (ckm) this.ˊ.get(i);
            if (o_ckm != null) {
                tabSpec.setIndicator(o_ckm.ˋ());
                return true;
            }
        }
        Logger.e("HomePageAdapter", "createTabSpec error navColumns = " + this.ˊ + ", position = " + i);
        return false;
    }

    public String ˊ(int i) {
        if (!(this.ˊ == null || this.ˊ.isEmpty())) {
            ckm o_ckm = (ckm) this.ˊ.get(i);
            if (o_ckm != null) {
                return o_ckm.ˊ();
            }
        }
        Logger.e("HomePageAdapter", "getTabSpecTag error navColumns = " + this.ˊ + ", position = " + i);
        return String.valueOf(i);
    }

    private void ॱ(Fragment fragment, int i) {
        if ((fragment instanceof cid) && ((cid) fragment).ʽʼ() != i) {
            ((cid) fragment).ॱᐝ(i);
        }
    }

    private void ॱ(int i) {
        ckm o_ckm = (ckm) this.ˊ.get(i);
        if (o_ckm != null && "gss|discovery".equals(cju.ॱ(o_ckm.ˊ()))) {
            djp.ˎ().ˏ(true);
        }
    }
}
